<html>
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width,initial-scale=1.0">
        <title>修改信息页面</title>
    </head>
    <body>
        <center>
            <?php
            include "common\menu.php";
            require "common\conn.php";
            $stu_get = $_GET['stu_no'];
            $sql = "SELECT * from stu where stu_no='{$stu_get}'";
            $result = $pdo->query($sql);
            $stu_arr = $result->fetch(PDO::FETCH_ASSOC); //执行sql,query返回一个PDOstatement对象
            if($_SERVER['REQUEST_METHOD'] == 'POST') {
                print_r($_POST);
                $stu_no = $_POST['stu_no'];
                $stu_name = $_POST['stu_name'];
                $gender = $_POST['gender'];
                $telephone = $_POST['telephone'];
                $age = $_POST['age'];
                $college = $_POST['college'];

                $sql = "UPDATE stu set stu_no='{$stu_no}',stu_name='{$stu_name}',gender='{$gender}',telephone='{$telephone}',age='{$age}',college='{$college}' where stu_no='{$stu_get}'";
                $result = $pdo->exec($sql);
                header('Location:index.php');
            }
            ?>       
            <h3>修改学生信息</h3>
            <form action="" method="post">
                <table>
                    <tr>
                        <td>学号：</td>
                        <td><input type="text" name="stu_no" value="<?php echo $stu_arr['stu_no']?>" required></td>
                    </tr>
                    <tr>
                        <td>姓名：</td>
                        <td><input type="text" name="stu_name" value="<?php echo $stu_arr['stu_name']?>" required></td>
                    </tr>
                    <tr>
                        <td>性别：</td>
                        <td>男<input type="radio" name="gender" value="男" <?php if($stu_arr['gender'] == '男') {echo "checked";}?> required>
                        女<input type="radio" name="gender" value="女" <?php if($stu_arr['gender'] == '女') {echo "checked";}?> required></td>
                    </tr>
                    <tr>
                        <td>电话：</td>
                        <td><input type="text" name="telephone" value="<?php echo $stu_arr['telephone']?>" required></td>
                    </tr>
                    <tr>
                        <td>年龄：</td>
                        <td><input type="text" name="age" value="<?php echo $stu_arr['age']?>" required></td>
                    </tr>
                    <tr>
                        <td>学院：</td>
                        <td><input type="text" name="college" value="<?php echo $stu_arr['college']?>" required></td>
                    </tr>
                    <tr align="center">
                        <td colspan="2">
                            <input type="submit" value="修改">
                            <input type="reset" value="重置">
                        </td>
                    </tr>
                </table>
            </form>
        </center>
    </body>
</html>